import random,string
from random import choice
class CommonTool(object):

    def __init__(self, database_source):
        self.database_source = database_source

    def get_data_source(self, database, cmdopt):
        database_source = self.database_source
        for database_value in database_source[cmdopt]:
            if database_value["database"] == database:
                return database_value["object"], database_value["pool"]

    @staticmethod
    def generate_email():
        num_list=[]
        for i  in range(0,5):
            num_list.append(random.randint(1,10))
        email_prefix=''.join('%s'%num for num in num_list)
        email_suffix='@qq.com'
        generate_email=email_prefix+email_suffix
        #print(generate_email)
        return generate_email

    @staticmethod
    def generate_string():
        test_name=''.join(random.sample('abcdefghijklmnopqrstuvwxyz',6))
        print(test_name)
        return test_name

    @staticmethod
    def generate_first_name():
        first_name='firstname' + ''.join(random.sample('abcdefghijklmnopqrstuvwxyz',4))
        print(first_name)
        return first_name

    @staticmethod
    def generate_last_name():
        last_name='lastname' + ''.join(random.sample('abcdefghijklmnopqrstuvwxyz',4))
        print(last_name)
        return last_name

    @staticmethod
    def generate_phone_number():
        numbers = string.digits
        randomNumber = '159'+''.join(choice(numbers) for _ in range(8))
        print(randomNumber)
        return randomNumber

    @staticmethod
    def generate_edit_role_name():
        edit_role_name = 'edit'+''.join(random.sample('abcdefghijklmnopqrstuvwxyz', 6))
        print(edit_role_name)
        return edit_role_name

    @staticmethod
    def generate_edit_org_name():
        edit_org_name='edit'+''.join(random.sample('abcdefghijklmnopqrstuvwxyz', 6))
        print(edit_org_name)
        return edit_org_name


    @staticmethod
    def generate_less_than_certain_value(num):
            #number=random.randint(21,num-1)
            number=random.randint(1,num+21)
            print(number)
            return str(number)





#CommonTool().generate_email()
#CommonTool().generate_string()

